package cheqex.update.controllers;
import java.util.ArrayList;
import java.sql.Date;
import java.util.List;

import cheqex.dao.DepositCash;
import cheqex.dao.DepositCashPeer;
import cheqex.dao.DepositCheck;
import cheqex.dao.DepositCheckPeer;


public class DepositController {
	private String date;
	
	public DepositController(String userDate){
		this.date = userDate;
	}

	public static boolean addDepositCash(String orNumber, java.sql.Date date, int amount, String particular, int id){
		try{
			if(DepositCashPeer.addDepositCash(orNumber, amount, particular, date, id))
				return true;
			else
				return false;
		} catch (Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean editDepositCash(String orNumber, int amount, String particular, java.sql.Date date){
		try{
			DepositCashPeer.editDepositCash(orNumber, amount, particular, date);
			return true;
		} catch (Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean deleteDepositCash(String orNumber, java.sql.Date date){
		try{
			DepositCashPeer.deleteDepositCash(orNumber, date);
			return true;
		} catch (Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	public static int getAmtCash(String key){
		try{
			List<DepositCash> list = DepositCashPeer.getData(key);
			DepositCash depositCash = list.get(0);
			return depositCash.getAmount();
		}catch (Exception e){
			e.printStackTrace();
			return -9999;
		}
	}
	
	public static String getParticularCash(String key){
		try{
			List<DepositCash> list = DepositCashPeer.getData(key);
			DepositCash depositCash = list.get(0);
			return depositCash.getParticulars();
		}catch (Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	public static boolean addDepositCheck(String prNumber, java.sql.Date date, int amount, String particular, int id){
		try{
			if(DepositCheckPeer.addDepositCheck(prNumber, amount, particular, date, id))
				return true;
			else return false;
		} catch (Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean editDepositCheck(String prNumber, int amount, String particular,  java.sql.Date date){
		try{
			DepositCheckPeer.editDepositCheck(prNumber, amount, particular, date);
			return true;
		} catch (Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean deleteDepositCheck(String prNumber, java.sql.Date date){
		try{
			DepositCheckPeer.deleteDepositCheck(prNumber, date);
			return true;
		} catch (Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	public static int getAmtCheck(String key){
		try{
			List<DepositCheck> list = DepositCheckPeer.getData(key);
			DepositCheck depositCheck = list.get(0);
			return depositCheck.getAmount();
		}catch (Exception e){
			e.printStackTrace();
			return -9999;
		}
	}
	
	public static String getParticularCheck(String key){
		try{
			List<DepositCheck> list = DepositCheckPeer.getData(key);
			DepositCheck depositCheck = list.get(0);
			return depositCheck.getParticulars();
		}catch (Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	public static int validateDataToBeAdded(String number, int amount, String particular){
		int error_id=8;
		if(number.isEmpty()){
			if(Integer.toString(amount).isEmpty() || amount==-9999){
				if(particular.isEmpty())error_id=3; //missing number & amount & particular
				else error_id=2; //missing number & amount 
			}else if(particular.isEmpty()) error_id=4; //missing number & particular
			else error_id=1;//missing number
		}else if(Integer.toString(amount).isEmpty() || amount==-9999){
			if(particular.isEmpty()) error_id = 5; //missing amount & particular
			else error_id=6; //missing amount
		}else if(particular.isEmpty()) error_id=7; //missing particular
		
		return error_id;
	}
	
	public static boolean isNumeric(String input){ //checks if number
		try 
		{
			 char[] ch = input.toCharArray(); 
			 for(int i = 0; i < input.length();i++) {
		            if( Character.isDigit(ch[i]) ) 
		            	continue; 
		            else return false;
			 }
			 return true;
		}catch (NumberFormatException nfe) {
			nfe.printStackTrace();
			return false;
		}
	
	}
	
	
	public static boolean findOR(String orNumber, java.sql.Date date){
		try{
			if(DepositCashPeer.getOR(orNumber, date)!=null)
				return true;
			else return false;
		} catch (Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean findPR(String prNumber, java.sql.Date date){
		try{
			if(DepositCheckPeer.getPR(prNumber, date)!=null)
				return true;
			else return false;
		} catch (Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	
	

}
